#include "set.h"
#include "ui_set.h"

#include <QFile>
#include <QSqlTableModel>

Set::Set(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Set)
{
    ui->setupUi(this);

    setAutoFillBackground(true);
    // 樱
    setPalette(QPalette(QColor(254,233,225)));

    ui->groupBox->setAutoFillBackground(true);
    // 褪红
    ui->groupBox->setPalette(QPalette(QColor(248,195,205)));

    ui->RemindTime->setMinimum(1);  // 最小值
    ui->RemindTime->setMaximum(60);  // 最大值
    ui->RemindTime->setSingleStep(1);  // 步长

    ui->WorkTime->setMinimum(1);  // 最小值
    ui->WorkTime->setMaximum(60);  // 最大值
    ui->WorkTime->setSingleStep(1);  // 步长

    ui->RelaxTime->setMinimum(1);  // 最小值
    ui->RelaxTime->setMaximum(60);  // 最大值
    ui->RelaxTime->setSingleStep(1);  // 步长
}

Set::~Set()
{
    delete ui;
}

void Set::SetDefault(int RmT, int WkT, int RlT){
    ui->RemindTime->setValue(RmT);
    ui->WorkTime->setValue(WkT);
    ui->RelaxTime->setValue(RlT);
};

void Set::on_buttonBox_accepted()
{
    QFile file("init.dat");
    if(!file.open(QIODevice::WriteOnly|QIODevice::Text))//以读的方式打开文件
    {
        return;
    }
    else{
        file.write(QString::number(ui->RemindTime->value()).toStdString().c_str());
        file.write("\n");
        file.write(QString::number(ui->WorkTime->value()).toStdString().c_str());
        file.write("\n");
        file.write(QString::number(ui->RelaxTime->value()).toStdString().c_str());
        file.write("\n");
    }
    file.close();//关闭文件
}

void Set::on_buttonBox_rejected()
{
    hide();
}

void Set::on_WorkTime_valueChanged(int value)
{
    ui->ValueWk->setText(QString::number(value));
}

void Set::on_RemindTime_valueChanged(int value)
{
    ui->ValueRm->setText(QString::number(value));
}

void Set::on_RelaxTime_valueChanged(int value)
{
    ui->ValueRl->setText(QString::number(value));
}
